Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

441
Visualizações
Clicking cookie button with Selenium 4 error: object[] has no size and location

I've been attempting to click a button in a pop-up with selenium, but I'm getting the following error:

object [HTMLDivElement] has no size and location

I have tried the normal way, with just click, since it is in the viewport and I am waiting for the page to fully load:

let pressCookieButton = await driver.findElement(By.xpath('//a[@class="btn-actiune btn-actiune--principal"]/..'))
await pressCookieButton.click();

But this does not work. It says

Element not interactible

Then, i tried to click using actions:

let pressCookieButton = await driver.findElement(By.xpath('//a[@class="btn-actiune btn-actiune--principal"]/..'))
const actions = driver.actions({ async: true });
await actions.click(pressCookieButton).perform();

But i get:

object [HTMLDivElement] has no size and location

The HTML that I am attempting to click is the following:

<div class="col-md-4 col-sm-4 col-xs-12"> 
    <a href="javascript:;" onclick="modCookies.updatePermisiuniCookies('toate');" class="btn-actiune btn-actiune--principal">Accept toate cookie-urile</a>  
</div>

Below is the full code:

const {Builder} = require('selenium-webdriver');
const {By} = require('selenium-webdriver');

(async function helloSelenium() {

    let driver = await new Builder().forBrowser('chrome').build();

    try{

        await driver.get('https://www.imobiliare.ro/vanzare-apartamente/timisoara/matei-basarab/apartament-de-vanzare-3-camere-XCB61020C');
    
        await driver.sleep(7000);
        console.log("clicking")
    
        
        let pressCookieButton = await driver.findElement(By.xpath('//a[@class="btn-actiune btn-actiune--principal"]/..'))

        
        const actions = driver.actions({ async: true });
        await actions.click(pressCookieButton).perform();
    
        //findElement(By.className('btn-actiune btn-actiune--principal'));
        await driver.sleep(10000);
    
        await pressCookieButton.click();
    
    }catch(error){
        console.log(error)

        await driver.sleep(5000);

        // await driver.quit()
    }
    
})();
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As you can see from the GIF below, the xpath matches two elements and by using driver.findElement you are selecting the first one, while the correct one is the second.

So you should either use driver.findElements instead of driver.findElement and then select the second element, or use a selector targetting only the correct element, such as

driver.findElement(By.cssSelector('div[class*="vizibil-informare"] a[class*="principal"]'))

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda